package com.acme.bankapp.domain.bank;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import static com.acme.bankapp.service.bank.BankService.addAccount;
import static com.acme.bankapp.service.bank.BankService.addClient;

public class BankApplication {
	
	public void modifyBank(Bank bank, int idOfClient, String depositOrWithdraw, 
			int numOfAccount, int sum){
		
		ArrayList<Client> clients = bank.getClients();
		if(!(depositOrWithdraw.equals("deposit") || depositOrWithdraw.equals("withdraw")) 
				|| clients.size() < idOfClient + 1){
			System.out.println("Wrong format input data");
		}
		else if(clients.get(idOfClient).getAccounts().size() < numOfAccount + 1){
			System.out.println("Wrong format input data");
		}
		else{
			if(depositOrWithdraw.equals("deposit")){
				clients.get(idOfClient).getAccounts().get(numOfAccount).deposit(sum);
			}
			else if(depositOrWithdraw.equals("withdraw"))
				clients.get(idOfClient).getAccounts().get(numOfAccount).withdraw(sum);
		}
	}
	
	public void printBalance(Bank b){
		ArrayList<Client> clients = b.getClients();
		for (Client cl : clients){
			ArrayList<Account> accounts = cl.getAccounts();
			for(Account ac : accounts){
				cl.getClientSalutation();
				System.out.println(" " + ac.getBalance());
			}			
		}
	}
	
	public static void main(String[] args){
		
		BankApplication bankApplication = new BankApplication();
		
		Bank bank = new Bank();		
		addClient(bank, new Client("Drozdov", Gender.MALE, 150, 50));
		System.out.println("\n");
		addClient(bank, new Client("Ivanova", Gender.FEMALE, 150));

		Bank anotherBank = new Bank(
				new ClientRegisrationListener(){			
					public void onClientAdded(Client c){
						System.out.print("Notification email for client ");
						c.getClientSalutation();
						System.out.print(" to be send");}			
				}, 
				new ClientRegisrationListener(){
					public void onClientAdded(Client c){
						System.out.print("Notification email for client ");
						c.getClientSalutation();
						System.out.print(" to be send");
					}			
				});
		
		System.out.println("\n");
		addClient(bank, new Client("Sidorov", Gender.MALE, 2000, 500));
		System.out.println("\n");
		addClient(bank, new Client("Egorova", Gender.FEMALE, 1500));
  }	
}
